from django.db import models


# Create your models here.

# 新建一张分类表（id,名称，父id）
class Kind(models.Model):
    name = models.CharField(max_length=50)
    # kid = models.IntegerField()
    father = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='父ID')

    class Meta:
        db_table = "kind"


# 新建一张商品表（id，名称，价格，库存，内容，总评论数，分类id）
class Goods(models.Model):
    goodsname = models.CharField(max_length=50)
    goodsprice = models.DecimalField(max_digits=7, decimal_places=2)
    goodsstock = models.IntegerField()
    content = models.TextField()
    comment = models.IntegerField()
    gid = models.ForeignKey('Kind', on_delete=models.CASCADE)

    class Meta:
        db_table = "goods"


# 题
# 班级表
class Sclass(models.Model):
    user = models.CharField(max_length=30)

    class Meta:
        db_table = 'sclass'


class Course(models.Model):
    name = models.CharField(max_length=30)
    cla = models.ForeignKey(Sclass, on_delete=models.CASCADE, related_name='courses')

    class Meta:
        db_table = 'course'


class Stu(models.Model):
    name = models.CharField(max_length=30)
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=200)
    cla = models.ForeignKey(Sclass, on_delete=models.CASCADE)

    class Meta:
        db_table = 'stu'


# 作业
# 用户表
class Suser(models.Model):
    name = models.CharField(max_length=20, verbose_name='姓名')
    username = models.CharField(max_length=225, verbose_name='用户名')
    password = models.CharField(max_length=255, verbose_name='密码')

    class Meta:
        db_table = 'suser'


# 商品表
class Shop(models.Model):
    name = models.CharField(max_length=20, verbose_name='名称')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价格')
    stock = models.IntegerField(default=999, verbose_name='库存')
    pic = models.ImageField(verbose_name='图片')
    comments = models.IntegerField(default=0, verbose_name='评论数')

    class Meta:
        db_table = 'shop'
        verbose_name = '商品表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 评论表
class Comtent(models.Model):
    user = models.ForeignKey(Suser, on_delete=models.CASCADE)
    shop = models.ForeignKey(Shop, on_delete=models.CASCADE, related_name='con')
    content = models.TextField()

    class Meta:
        db_table = 'comtent'


# ####################################
# 校区表
class ACampus(models.Model):
    cname = models.CharField(max_length=100)

    class Meta:
        db_table = "acampus"


# 班级表
class AGrade(models.Model):
    gname = models.CharField(max_length=100)
    school = models.ForeignKey(ACampus, on_delete=models.CASCADE)

    class Meta:
        db_table = 'agrade'


# 学员表
class AStudent(models.Model):
    sname = models.CharField(max_length=100)
    gclass = models.ForeignKey(AGrade, on_delete=models.CASCADE)

    class Meta:
        db_table = "astudnet"


# 所有学员表
class AOfficer(models.Model):
    oname = models.CharField(max_length=100)
    astu = models.ForeignKey(AStudent, on_delete=models.CASCADE)

    class Meta:
        db_table = "aofficer"


# 第一套题
# 学生表
class Teacher(models.Model):
    username = models.CharField(max_length=100, unique=True, verbose_name='老师用户名')
    password = models.CharField(max_length=200, verbose_name='密码')

    class Meta:
        db_table = "teacher"


class Tstu(models.Model):
    name = models.CharField(max_length=100, unique=True, verbose_name='学生姓名')
    age = models.IntegerField(verbose_name='学生年龄')
    teacher = models.ForeignKey(Teacher, on_delete=models.SET_NULL, null=True, blank=True, verbose_name='绑定学生表外键')

    class Meta:
        db_table = "tstu"
